import {ajax} from './Promise_AJAX.js'
import {getCookie} from './getCookie.js'
let main =document.querySelector('main'),
    {phone,name,token}=getCookie()
// 重新登陆
if((token ==undefined)||(token=='')){
    alert('请登录')
    location.href='./index.html' 
}
;(async () =>{
    // 获取所有预约信息
   let getBook= await ajax(`http://newshopapi.0melon0.cn/api/f_user/report`,{ "phone":phone, "name":name },'POST')
    // 获取最新预约信息
    let bookData= getBook.result[getBook.result.length-1]
   console.log('最新的预约',bookData)
   let id=bookData.id
    // 获取场次时间
    let getTimeName = await ajax(`http://newshopapi.0melon0.cn/api/f_user/chooseday?token=${token}&day_time=${bookData.day_time}`),
        show_name = getTimeName.result.list[bookData.show_id-1].show_name
    // 获取二维码
    let getQRcode =await ajax(`http://newshopapi.0melon0.cn/api/f_user/Qrcode?token=${token}&id=${id}`)
    main.innerHTML= `<p>姓名：<span id="uname">${name}</span></p>      
            <p>日期：<span id="uname">${bookData.day_time}</span></p>
            <p>场次：<span id="count">${show_name}</span></p>
            <div class="img"><img src="${getQRcode.data.data}"></div>`
})()